﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace P3SS.FailedMail
{
	/// <summary>
	/// A mail item that failed to be submitted, and the reason why
	/// </summary>
	public class FailedMailItem
	{
		#region Constructors
		/// <summary>
		/// Default constructor.
		/// </summary>
		public FailedMailItem()
		{
			FailureReason = "";
			MailItem = "";
			EmailAddress = "";
		}
		#endregion
		#region Properties
		/// <summary>
		/// The Mail Item that failed to send
		/// </summary>
		public string MailItem { get; set; }

		/// <summary>
		/// The exception thrown when attempting to send
		/// </summary>
		public string FailureReason { get; set; }

		/// <summary>
		/// The email address trying to be sent to
		/// </summary>
		public string EmailAddress { get; set; }

		/// <summary>
		/// SMTP server to use
		/// </summary>
		public string SMTPServer { get; set; }
		#endregion
		#region Public Methods
		/// <summary>
		/// Displays this FailedMailItem as a human readable string
		/// </summary>
		/// <returns>The first 30 characters of the message</returns>
		public override string ToString()
		{
			string output = "";

			if (MailItem.Contains("::::::"))
			{
				output = MailItem.Substring(MailItem.IndexOf("::::::") + 6, 30).Trim();
			}
			else if (MailItem.Length > 30)
			{
				output = MailItem.Substring(0, 30).Trim();
			}
			else
			{
				output = MailItem.Trim();
			}

			if (output.Length < MailItem.Length)
			{
				output += "...";
			}

			return output;
		}
		#endregion
	}
}
